from applications.extensions import ma
from marshmallow import fields


class MsgUrlOutSchema(ma.Schema):
    id = fields.Integer()
    msgTitle = fields.Str(attribute="title")
    msgUrl = fields.Str(attribute="href")
    msgContent = fields.Str(attribute="content")
    msgTime = fields.Str(attribute="time")
    category = fields.Method("get_category")
    finish = fields.Integer()
    enable = fields.Str()
    remark = fields.Str()
    details = fields.Str()
    create_at = fields.DateTime()
    update_at = fields.DateTime()

    def get_category(self, obj):
        if obj.category != None:
            return obj.category.name
        return None
